/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slicktest.factories;

import java.util.List;
import org.newdawn.slick.SlickException;
import slicktest.entities.ImmobileEntity.ImmobileEntity;

import slicktest.entities.ImmobileEntity.Terrain;
import slicktest.entities.ImmobileEntity.Tower;

import slicktest.factories.marshallers.TerrainMarshaller;
import slicktest.factories.marshallers.TowerMarshaller;

/**
 *
 * @author enrightt
 */
public class GameEntityFactory {
    private static GameEntityFactory instance = new GameEntityFactory();
    private final String TERRAIN_PATH = "data/terrain";
    private final String TOWER_PATH = "data/towers";
    
    private TerrainMarshaller terrainMarshaller; 
    private TowerMarshaller towerMarshaller;

    private GameEntityFactory() {
        terrainMarshaller = new TerrainMarshaller(TERRAIN_PATH);
        towerMarshaller = new TowerMarshaller(TOWER_PATH);
    }

    public static GameEntityFactory getInstance() {
        return instance;
    }
    public Terrain createTerrain(String type) {
        Terrain result = null;
        
        try {
            result = (Terrain) terrainMarshaller.marshall(type);
        } catch (SlickException ex) {
            System.err.println(type + " is not in the list of known terrain");
        }
        
        return result;
    }

    public Tower createTower(String type) {
        Tower result = null;
        
        try {
            result = (Tower) towerMarshaller.marshall(type);
        } catch(SlickException ex) {
            System.err.println(type + " is not in the list of known towers");
        }

        return result;
    }

    public List<ImmobileEntity> getModelTowers() {
        return towerMarshaller.getModels();
    }
}
